//
//  XDMainViewController.m
//  iphone.mobileoa
//
//  Created by 李亚春 on 13-5-22.
//  Copyright (c) 2013年 Epoint. All rights reserved.
//

#import "XDMainViewController.h"
#import "MainViewIconPanel.h"
#import "SynTask.h"
#import "DBFrameService.h"

@interface XDMainViewController ()

@end

@implementation XDMainViewController

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    self.title = [NSString stringWithFormat:@"%@%@",[[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleDisplayName"],[[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleShortVersionString"]];
    self.navigationItem.leftBarButtonItem = nil;
    self.navigationItem.hidesBackButton = YES;
    float panelHeight = MainViewIconPanel.getPanelHeight;
    CGFloat midy = [[UIScreen mainScreen]bounds].size.height/2-panelHeight/2-44;
    
    NSString *NewWaitHandleCount = [[intentParams objectForKey:@"NewWaitHandleCount"]retain];
    NSString *NewMailsCount = [[intentParams objectForKey:@"NewMailsCount"]retain];
    
    NSMutableDictionary *iconParams = [[NSMutableDictionary alloc]init];
    [iconParams setObject:NewMailsCount forKey:@"MailCount"];
    [iconParams setObject:NewWaitHandleCount forKey:@"DBCount"];
    MainViewIconPanel *mainPanel = [[MainViewIconPanel alloc]initWithFrame:CGRectMake(0, midy, 320, panelHeight) context:self param:iconParams];
    [self.view addSubview:mainPanel];
    
    if ([DBFrameService getUserCount]==0||[DBFrameService getOuCount]==0) {
        [self showMBPHUDWithMessage:@"正在同步数据..."];
        syntaskguid = [[[SynTask alloc]initWithContext:self andParams:self.getPassDictionary]startTask];
    }
    else
    {
        
        
        NSString *dbtip = @"";
        if (NewWaitHandleCount.intValue>0) {
            dbtip = [NSString stringWithFormat:@"您当前有%@件待办事宜！",NewWaitHandleCount];
        }
        
        NSString *mailtip = @"";
        if (NewMailsCount.intValue>0) {
            mailtip = [NSString stringWithFormat:@"您当前有%@封未读邮件！",NewMailsCount];
        }
        NSString *displayname = [DBFrameService getConfigValue:EP_ConfigKey_displayname];
        NSString *tip = [NSString stringWithFormat:@"%@，您好！\n%@\n%@",displayname,dbtip,mailtip];
        
        [UITool toast:[tip retain]];
    }

}

-(void)refreshUIWithThreadGuid:(NSString *)threadGuid andData:(NSObject *)obj
{
    [self hideMBPHUD];
    if ([syntaskguid isEqualToString:threadGuid]) {
        
    }
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
